package com.geezdata.cps.sdk3rd.kaola.request;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.hibernate.validator.constraints.NotBlank;

import com.geezdata.cps.base.request.BaseRequest;
import com.geezdata.cps.sdk3rd.kaola.response.KaolaResult;

/**
 * 考拉接口请求通用父类<br>
 * &nbsp;<br>
 * 系统级别输入参数：<br>
 * <li>method：必须，API接口名称
 * <li>access_token：必须， Oauth的token
 * <li>app_key String：必须，应用的app_key
 * <li>sign：必须，签名
 * <li>timestamp：必须，请求的时间戳。格式为yyyy-MM-dd HH:mm:ss，例如：2015-11-06 13:23:30。注意：与当前时间差不超过6分钟
 * <li>v：可选，API协议版本号，可选值:1.0，默认:1.0<br>
 * &nbsp;<br>
 * @param <T>
 */
public abstract class KaolaRequest<T extends KaolaResult> extends BaseRequest {
    @NotBlank(message = "methodName 不能为空！")
	protected String methodName = null;

    @NotBlank(message = "timestamp 不能为空！")
    private String timestamp = null;

    private String v = "1.0";

    protected SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public KaolaRequest() {
        super();
        setTimestamp(new Date()); 
    }

    public String getMethodName() {
        return methodName;
    }

    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = sdf.format(timestamp);
    }

    public String getV() {
        return v;
    }

    public void setV(String v) {
        this.v = v;
    }

    /** 
     * 获得考拉部分系统级输入参数
     */
    public Map<String, Object> getHttpParams() {
        Map<String, Object> httpParams = new HashMap<String, Object>();
        httpParams.put("method", methodName);
        httpParams.put("timestamp", timestamp);
        httpParams.put("v", v);
        return httpParams;
    }
    
    /** 
     * 获得考拉请求应用级输入参数
     */
    public abstract Map<String, Object> getAppParams();
    
    /**
     * 考拉接口返回的响应类型
     * @param <T>
     * 
     * @return Class<T>
     */
    public abstract Class<T> getResponseClass();
}
